#ifndef _ASYNCTCPLISTENSOCKIMPL_H_
#define _ASYNCTCPLISTENSOCKIMPL_H_

#include "stdafx.h"

class CTcpListenSocketImpl : public ITcpListen, public CUnknownImp
{
public:
    CTcpListenSocketImpl(void);
    virtual ~CTcpListenSocketImpl(void);

    BEGIN_STDCOM_MAP
    STDCOM_INTERFACE_ENTRY(ITcpListen)
    STDCOM_INTERFACE_ENTRY_UNKNOWN_(ITcpListen)
    END_STDCOM_MAP

public:
    HRESULT BindEvloop(ioevloop_t* loop);

public:
    // IIoDevice
    std_method(CloseIo)(UINT rw);
    std_method(BindIo)();
    std_method(OpenIo)();

    // ISocket
    std_method(BindEvent)(IBase* pSocketEvent);
    std_method(UnBindEvent)();
    std_method(CreateSock)();
    std_method(CloseSock)();
    std_method(IsOpen)();
    std_method(AttachSock)(_sock_t sock);
    std_method_(_sock_t, DetachSock)();
    std_method_(_sock_t, GetSock)();
    std_method(GetReadOperation)(IID id, IBase** pBase);
    std_method(GetWriteOperation)(IID id, IBase** pBase);

    // IListen
    std_method(Listen)(NET_ADDR addr, NET_PORT port);
    std_method(Listen6)(NET_ADDR addr, NET_PORT port);
    std_method(Accept)(int on);

    // ITcpListen
    std_method(BindAccept)(IBase* pAccept);
    std_method(UnBindAccpet)();

public:
    std_method(Acceptcb)(_sock_t s, SOCKADDR_PTR sa, socklen_t sl, crtid err);

private:
    _sock_t m_sock;
    _lComPtr<IAcceptListen> m_accept;
    SafePtr<ioevtcp_t*, default_free_safeptr> m_tcp;
    ioevloop_t* m_evloop;
};

#endif
